<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
export default {
  name: "App",
  watch() {
    
   window.onbeforeunload = function (e) {
      e = e || window.event;
      alert(1)
      let token = Vue.cookie.get("token");
      if (!token || !/\S/.test(token)) {
        Vue.cookie.delete("token");
        next({ name: "user" });
      }
    
      // 兼容IE8和Firefox 4之前的版本
      if (e) {
        e.returnValue = '关闭提示';
      }
    
      // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
      return '关闭提示';
    };
  },
  mounted(){
    
    window.onbeforeunload = function (e) {
      e = e || window.event;
      alert(1)
      let token = Vue.cookie.get("token");
      if (!token || !/\S/.test(token)) {
        Vue.cookie.delete("token");
        next({ name: "user" });
      }
    
      // 兼容IE8和Firefox 4之前的版本
      if (e) {
        e.returnValue = '关闭提示';
      }
    
      // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
      return '关闭提示';
    };
  }
};
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  margin-top: 60px;
  margin: 0 auto;
  width: 70%;
}
</style>
